/**
 * 2010(c) Copyright Oceansoft Information System Co.,LTD. All rights reserved.
 * <p>
 * Compile: JDK 1.6+
 * <p>
 * 版权所有(C)：江苏欧索软件有限公司
 * <p>
 * 公司名称：江苏欧索软件有限公司
 * <p>
 * 公司地址：中国苏州科技城青山路1号
 * <p>
 * 网址: http://www.oceansoft.com.cn
 * <p>
 * 作者: 090922(陈伟)
 * <p>
 * 文件名: com.oceansoft.mobile.econsole.business.sys.controller.SysUserController.java 
 * <p>
 * 类产生时间: 2014-5-19 0019 下午 13:03
 * <p>
 * 负责人: 090922(陈伟)
 * <p>
 * Email:javacspring@gmail.com
 * <p>
 * 所在组 : 掌上公安应用平台
 * <p>
 * 所在部门: 开发部--手持技术部
 * <p>
 * <p>
 */
package cn.com.oceansoft.business.os.controller;

import cn.com.oceansoft.business.base.controller.BaseController;
import cn.com.oceansoft.business.base.entity.Pager;
import cn.com.oceansoft.business.base.entity.Query;
import cn.com.oceansoft.business.base.entity.Result;
import cn.com.oceansoft.business.os.entity.User;
import cn.com.oceansoft.business.os.service.IUserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

import static org.springframework.web.bind.annotation.RequestMethod.*;

/**
 * 系统用户控制器
 *
 * @author: chenw
 * @time: 2014-5-19 0019 下午 13:03
 */
@Controller
@RequestMapping("user")
public class UserController extends BaseController {

    @Resource
    private IUserService userService;



    /**
     * 进入员工信息首页
     *
     * @return String
     */
    @RequestMapping(value = "index", method = GET)
    public String gotoUserIndex(Query query, Model model) {
        model.addAttribute("query", query);
        model.addAttribute("pager", userService.findByPage(query));
        return "os/user/list";
    }

    /**
     * 列表分页显示
     *
     * @param query 分页查询条件
     * @param model 数据Model
     * @return 页面地址
     */
    @RequestMapping(value = "list", method = POST)
    public String loadPageByCondition(Query query, Model model) {
        Pager<User> pager = userService.findByPage(query);
        model.addAttribute("query", query);
        model.addAttribute("pager", pager);
        return "os/user/list";
    }

    @ResponseBody
    @RequestMapping(value = "del/{regid}", method = DELETE)
    public Result delUser(@PathVariable("regid") String userId) {
        userService.delete(userId);
        return new Result();
    }


    @RequestMapping(value = "edit/{userid}", method = GET)
    public String editUser(@PathVariable("userid") int userId, Model model) {
        User user = userService.findUserById(userId);
        model.addAttribute("user", user);
        return "os/user/user-edit";
    }

    @ResponseBody
    @RequestMapping(value = "edit", method = POST)
    public Result editShow(User user) {
        return userService.updateUser(user);
    }

}
